package com.ui.basic.command;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.springmodules.validation.bean.conf.loader.annotation.handler.Length;
import org.springmodules.validation.bean.conf.loader.annotation.handler.NotBlank;

import com.common.basic.base.BaseCommand;
import com.ui.basic.ibatis.model.system.TblSMenu;

public class CommandMenu extends BaseCommand implements java.io.Serializable {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8102919869359325822L;
	private Long id;

	@NotBlank
	@Length(max = 30)
	private String code;
	@NotBlank
	@Length(max = 255)
	private String name;
	@Length(max = 255)
	private String link;
	@Length(max = 255)
	private String icon;
	private Boolean isView;
	private String description;
	private String prefix;
	private List<String> childs;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getLink() {
		return link;
	}

	public void setLink(String link) {
		this.link = link;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public Boolean getIsView() {
		return isView;
	}

	public void setIsView(Boolean isView) {
		this.isView = isView;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getPrefix() {
		return prefix;
	}

	public void setPrefix(String prefix) {
		this.prefix = prefix;
	}

	public void setChilds(List<String> childs) {
		this.childs = childs;
	}

	public static long getSerialVersionUID() {
		return serialVersionUID;
	}

	public int getLength() {
		int length = getName().length();
		for (Iterator<String> i = getChilds().iterator(); i.hasNext();) {
			String child = i.next();
			int idx = child.indexOf("|");
			child = child.substring(idx + 1, child.length());
			if (Integer.parseInt(child) > length)
				length = Integer.parseInt(child);
		}
		return length;
	}

	public List<String> getChilds() {
		if (childs == null)
			childs = new ArrayList<String>();
		return childs;
	}

	public void setProperty(TblSMenu menu) {
		this.id = menu.getId();
		this.name = menu.getMenuName();
		this.code = menu.getMenuCode();
		this.description = menu.getMenuDesc();
		this.icon = menu.getMenuIcon();
		this.isView = menu.getMenuViewable();
		this.link = menu.getMenuLink();
	}
}